/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.informet.ipd.struts.action;


import com.informet.ipd.modelo.vo.*;
import com.informet.ipd.modelo.dao.*;
import com.informet.ipd.struts.form.FichaForm;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JOptionPane;
import org.apache.commons.lang.StringUtils;


import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.chain.commands.servlet.SetContentType;

/**
 *
 * @author LYLA
 */
public class FichaAction extends DispatchAction {

    public ActionForward loadFichaMedallero(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;

        List listaeventos = new FichaDao().selectEventoMed();
        List listapaises = new FichaDao().selectPaisMed();
        //List listadiscip = new FichaDao().selectListDisc();
        form1.setListaeventos(listaeventos);
        form1.setListapais(listapaises);
        //form1.setListadiscip(listadiscip);
        return mapping.findForward("fichaMedallero");
    }

    public ActionForward loadFichaSatisfaccion(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        form1.setCodRegion("-1");
        form1.setFechasatisfaccion("");
        form1.setNomevento("");
        form1.setGenero(0);
        form1.setEdad(0);
        form1.setPartic(0);
        form1.setSatdoc(0);
        form1.setSateq(0);
        form1.setSatmat(0);
        form1.setSatinf(0);
        form1.setSatpunt(0);
        form1.setSatprog(0);
        form1.setOpinion(0);
        form1.setComentario("");
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        return mapping.findForward("fichaSatisfaccion");
    }

    public ActionForward loadFichaInfraestructurainicial(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        return mapping.findForward("fichaInfraestructurainicial");
    }


    public ActionForward loadFichaInfraestructurainicialmantenimiento(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        return mapping.findForward("fichaInfraestructurainicialmantenimiento");
    }


    public ActionForward loadFichaInfraestructura(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        /*form1.setCodRegion("-1");
        form1.setFechasatisfaccion("");
        form1.setNomevento("");
        form1.setGenero(0);
        form1.setEdad(0);
        form1.setPartic(0);
        form1.setSatdoc(0);
        form1.setSateq(0);
        form1.setSatmat(0);
        form1.setSatinf(0);
        form1.setSatpunt(0);
        form1.setSatprog(0);
        form1.setOpinion(0);
        form1.setComentario("");*/
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        return mapping.findForward("fichaInfraestructura");
    }

    public ActionForward loadFichaAdministrativa(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        form1.setAnio(0);
        form1.setEqu(0);
        form1.setRemacon(0);
        form1.setSede(0);
        form1.setDireccion("");
        form1.setCodRegion("-1");
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        return mapping.findForward("fichaAdministrativa");
    }



    public ActionForward loadEquipamiento(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        int coddetinf = Integer.parseInt(request.getParameter("coddetinf"));
        form1.setCoddetinfr(coddetinf);
        List listadisc = new FichaDao().selectListDiscEqu();
        form1.setListadiscip(listadisc);
        return mapping.findForward("equipamiento");
    }

    public ActionForward loadEquipamientoMod(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        int coddetinf = Integer.parseInt(request.getParameter("coddetinf"));
        form1.setCoddetinfr(coddetinf);
        List listadisc = new FichaDao().selectListDiscEqu();
        form1.setListadiscip(listadisc);
        return mapping.findForward("equipamientomod");
    }



    public ActionForward listarFichaSatisfaccion(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        List listTableSatisfaccion = new FichaDao().selectListSatisfaccion();
        form1.setListSatisfaccion(listTableSatisfaccion);
        return mapping.findForward("fichaSatisfaccionIdentificacion");
    }

    public ActionForward listarEventoMedalla(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        List listTableEventMedallero = new FichaDao().selectListEventoMedallero();
        form1.setListaEventoMedallero(listTableEventMedallero);
        return mapping.findForward("fichaMedalleroIdentificacion");
    }

    public ActionForward listarFichaInfraestructura(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        List listTableInfDep = new FichaDao().selectListInfDep();
        form1.setListaInfrDep(listTableInfDep);
        return mapping.findForward("fichaInfraestructuraIdentificacion");
    }

    public ActionForward listarFichaAdministrativa(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        FichaForm form1 = (FichaForm) form;
        List listTableInfAdm = new FichaDao().selectListInfAdm();
        form1.setListaInfrAdm(listTableInfAdm);
        return mapping.findForward("fichaAdministrativaIdentificacion");
    }

    public ActionForward editarFichaInfraestructura(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        FichaForm form1 = (FichaForm) form;
        int cod = Integer.parseInt(request.getParameter("pk"));
        FichaVO vo = new FichaDao().selectListInfDepId(cod);
        form1.setCodinfrdep(vo.getNUM_CODINFDEP_PK());
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        List listProvincia=new ProgEstrDao().getComboProvincia(vo.getNUM_CODDPTO_PK());
        form1.setListProvincia(listProvincia);
        List listDistrito=new ProgEstrDao().getComboDistrito(vo.getNUM_CODPRV_PK());
        form1.setListDistrtito(listDistrito);
        form1.setCodRegion(vo.getNUM_CODDPTO_PK());
        form1.setCodProvincia(vo.getNUM_CODPRV_PK());
        form1.setCodDistrito(vo.getNUM_CODDIST_PK());
        form1.setAnio(vo.getNUM_ANIO());
        form1.setTipoinfr(vo.getTX_TIPOINF());
        return mapping.findForward("fichaInfraestructuraEdicion");
    }
    
    public ActionForward editarFichaInfraestructuraAdm(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        FichaForm form1 = (FichaForm) form;
        int cod = Integer.parseInt(request.getParameter("pk"));
        FichaVO vo = new FichaDao().selectListInfAdmId(cod);
        form1.setCodinfadm(vo.getNUM_CODINFADMIN_PK());
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        List listProvincia=new ProgEstrDao().getComboProvincia(vo.getNUM_CODDPTO_PK());
        form1.setListProvincia(listProvincia);
        List listDistrito=new ProgEstrDao().getComboDistrito(vo.getNUM_CODPRV_PK());
        form1.setListDistrtito(listDistrito);
        form1.setCodRegion(vo.getNUM_CODDPTO_PK());
        form1.setCodProvincia(vo.getNUM_CODPRV_PK());
        form1.setCodDistrito(vo.getNUM_CODDIST_PK());
        form1.setAnio(vo.getNUM_ANIO());
        form1.setDireccion(vo.getTX_DIRECCION());
        form1.setSede(vo.getNUM_SEDE());
        form1.setRemacon(vo.getNUM_REMAC());
        form1.setEqu(vo.getNUM_EQU());
        form1.setFlagtipeq1(vo.getNUM_TIPOEQU1());
        form1.setFlagtipeq2(vo.getNUM_TIPOEQU2());
        form1.setFlagtipeq3(vo.getNUM_TIPOEQU3());
        return mapping.findForward("fichaAdministrativaEdicion");
    }






    public ActionForward editarFichaSatisfaccion(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        FichaForm form1 = (FichaForm) form;
        int cod = Integer.parseInt(request.getParameter("pk"));
        FichaVO vo = new FichaDao().selectListSatisfaccionId(cod);
        form1.setCodsatisfaccion(vo.getNUM_CODSATISF_PK());
        List region = new FichaDao().getRegion();
        form1.setListRegion(region);
        List listProvincia=new ProgEstrDao().getComboProvincia(vo.getNUM_CODDPTO_PK());
        form1.setListProvincia(listProvincia);
        List listDistrito=new ProgEstrDao().getComboDistrito(vo.getNUM_CODPRV_PK());
        form1.setListDistrtito(listDistrito);
        form1.setCodRegion(vo.getNUM_CODDPTO_PK());
        form1.setCodProvincia(vo.getNUM_CODPRV_PK());
        form1.setCodDistrito(vo.getNUM_CODDIST_PK());
        form1.setFechasatisfaccion(vo.getDT_FECHAENCUESTA());
        form1.setNomevento(vo.getTX_DESCEVENTO());
        form1.setGenero(vo.getNUM_GENERO());
        form1.setEdad(vo.getNUM_EDAD());
        form1.setPartflag(vo.getNUM_PART());
        form1.setSatdoc(vo.getNUM_SATDOC());
        form1.setSateq(vo.getNUM_SATEQU());
        form1.setSatmat(vo.getNUM_SATMAT());
        form1.setSatinf(vo.getNUM_SATINFR());
        form1.setSatpunt(vo.getNUM_SATPUNT());
        form1.setSatprog(vo.getNUM_SATPROG());
        form1.setOpinion(vo.getNUM_OPINION());
        form1.setComentario(vo.getTX_COMENTARIO());
        return mapping.findForward("fichaSatisfaccionEdicion");
    }



    public ActionForward editarEventoMedallero(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        FichaForm form1 = (FichaForm) form;
        int cod = Integer.parseInt(request.getParameter("pk"));

        /*
        bean.setNUM_CODDETMEDALL_PK(rs.getInt("NUM_CODDETMEDALL_PK"));
        bean.setNUM_MEDALLAORO(rs.getInt("NUM_MEDALLAORO"));
        bean.setNUM_MEDALLAPLATA(rs.getInt("NUM_MEDALLAPLATA"));
        bean.setNUM_MEDALLABRONCE(rs.getInt("NUM_MEDALLABRONCE"));
        bean.setNUM_CODDISCMEDALL_PK(rs.getInt("NUM_CODDISCMEDALL_PK"));
         */



        FichaVO vo = new FichaDao().selectListEventoId(cod);
        form1.setCodcabmedall(vo.getNUM_CODCABMEDALL_PK());

        List listaeventos = new FichaDao().selectEventoMed();
        List listapaises = new FichaDao().selectPaisMed();
        //List listadiscip = new FichaDao().selectListDisc();




        form1.setListaeventos(listaeventos);
        form1.setListapais(listapaises);

        form1.setCodevento(vo.getNUM_CODEVENTMED_PK());
        form1.setCodperiodo(vo.getNUM_PERIODO());
        form1.setCodpais(vo.getNUM_CODPAIS_PK());
        return mapping.findForward("fichaMedalleroEdicion");
    }




    public ActionForward grabarFichaSatisfaccion(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
                FichaForm form1 = (FichaForm) form;
                int tipoOper = Integer.parseInt(request.getParameter("tipoOper"));
                int codsatisfaccion = form1.getCodsatisfaccion();
                String fechasatisfaccion = form1.getFechasatisfaccion();
                String nomevento = form1.getNomevento();
                String codDistrito = request.getParameter("codDistrito");
                int genero = form1.getGenero();
                int edad = form1.getEdad();
                int partic = form1.getPartic();
                int satdoc = form1.getSatdoc();
                int sateq = form1.getSateq();
                int satmat = form1.getSatmat();
                int particflag=Integer.parseInt(request.getParameter("partic"));
                if(particflag==1){
                    satdoc = 0;
                    sateq = 0;
                    satmat = 0;
                }
                int satinf = form1.getSatinf();
                int satpunt = form1.getSatpunt();
                int satprog = form1.getSatprog();
                int opinion = form1.getOpinion();
                String comentario = form1.getComentario();
                FichaVO fichaVO = new FichaVO(tipoOper, codsatisfaccion, fechasatisfaccion,nomevento,codDistrito,genero,edad,partic,satdoc,sateq,satmat,satinf,satpunt,satprog,opinion,comentario);
                new FichaDao().spManSatisfaccion(fichaVO);
                return loadFichaSatisfaccion(mapping, form, request, response);
    }

    

    public ActionForward grabarFichaAdministrativa(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
                FichaForm form1 = (FichaForm) form;
                int tipoOper = Integer.parseInt(request.getParameter("tipoOper"));
                int codinfadm = Integer.parseInt(request.getParameter("codinfadm"));
                int anio = Integer.parseInt(request.getParameter("anio"));
                String direccion = request.getParameter("direccion");
                int sede = Integer.parseInt(request.getParameter("sede"));
                int remacon = Integer.parseInt(request.getParameter("remacon"));
                int equ = Integer.parseInt(request.getParameter("equ"));
                int tipeq1 = Integer.parseInt(request.getParameter("tipeq1"));
                int tipeq2 = Integer.parseInt(request.getParameter("tipeq2"));
                int tipeq3 = Integer.parseInt(request.getParameter("tipeq3"));
                String codDistrito = request.getParameter("codDistrito");
                FichaVO fichaVO = new FichaVO(codinfadm, anio, direccion,sede,remacon,equ,tipeq1,tipeq2,tipeq3,codDistrito,tipoOper);
                new FichaDao().spManInfAdm(fichaVO);
                return loadFichaAdministrativa(mapping, form, request, response);
    }

    public ActionForward grabareditFichaAdministrativa(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
                FichaForm form1 = (FichaForm) form;
                int tipoOper = Integer.parseInt(request.getParameter("tipoOper"));
                int codinfadm = Integer.parseInt(request.getParameter("codinfadm"));
                int anio = Integer.parseInt(request.getParameter("anio"));
                String direccion = request.getParameter("direccion");
                int sede = Integer.parseInt(request.getParameter("sede"));
                int remacon = Integer.parseInt(request.getParameter("remacon"));
                int equ = Integer.parseInt(request.getParameter("equ"));
                int tipeq1 = Integer.parseInt(request.getParameter("tipeq1"));
                int tipeq2 = Integer.parseInt(request.getParameter("tipeq2"));
                int tipeq3 = Integer.parseInt(request.getParameter("tipeq3"));
                String codDistrito = request.getParameter("codDistrito");
                FichaVO fichaVO = new FichaVO(codinfadm, anio, direccion,sede,remacon,equ,tipeq1,tipeq2,tipeq3,codDistrito,tipoOper);
                new FichaDao().spManInfAdm(fichaVO);
                return listarFichaAdministrativa(mapping, form, request, response);
    }



    public ActionForward grabareditFichaSatisfaccion(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
                FichaForm form1 = (FichaForm) form;
                int tipoOper = Integer.parseInt(request.getParameter("tipoOper"));
                int codsatisfaccion = form1.getCodsatisfaccion();
                if(tipoOper==3){
                    codsatisfaccion = Integer.parseInt(request.getParameter("pk"));
                }
                String fechasatisfaccion = form1.getFechasatisfaccion();
                String nomevento = form1.getNomevento();
                String codDistrito = request.getParameter("codDistrito");
                int genero = form1.getGenero();
                int edad = form1.getEdad();
                int partic = form1.getPartic();
                int satdoc = form1.getSatdoc();
                int sateq = form1.getSateq();
                int satmat = form1.getSatmat();

                int particflag=Integer.parseInt(request.getParameter("partic"));
                if(particflag==1){
                    satdoc = 0;
                    sateq = 0;
                    satmat = 0;
                }
                int satinf = form1.getSatinf();
                int satpunt = form1.getSatpunt();
                int satprog = form1.getSatprog();
                int opinion = form1.getOpinion();
                String comentario = form1.getComentario();
                FichaVO fichaVO = new FichaVO(tipoOper, codsatisfaccion, fechasatisfaccion,nomevento,codDistrito,genero,edad,partic,satdoc,sateq,satmat,satinf,satpunt,satprog,opinion,comentario);
                new FichaDao().spManSatisfaccion(fichaVO);
                return listarFichaSatisfaccion(mapping, form, request, response);
    }



    
}
